package com.gxa.clientarticle.controller;

/*
 *
 *@author leijun
 *
 *@creating 2020/11/13 14:26
 *
 */

import com.gxa.clientarticle.exception.BusinessException;
import com.gxa.clientarticle.pojo.TypeTable;
import com.gxa.clientarticle.service.TypeTableService;
import com.gxa.clientarticle.utils.JsonResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @ClassName TypeTableController
 * @Description TODO
 * @Author 俊
 * @Date 2020/11/13 14:26
 * @Version 1.0
 */
@RestController
@RequestMapping("/type")
public class TypeTableController {

    @Resource
    TypeTableService typeTableService;

    @RequiresPermissions("19")
    @PostMapping("/add")
    public Map  add(@RequestBody TypeTable typeTable){
        JsonResult jsonResult = new JsonResult();
        Integer add = typeTableService.add(typeTable);
        if (add != 1){
            throw new BusinessException("添加失败");
        }
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        return jsonResult.getValues();
    }
    @RequiresPermissions("19")
    @PostMapping("/update")
    public Map  update(@RequestBody TypeTable typeTable){
        JsonResult jsonResult = new JsonResult();
        Integer add = typeTableService.update(typeTable);
        if (add != 1){
            throw new BusinessException("修改失败");
        }
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getValues();
    }

    @RequiresPermissions("19")
    @PostMapping("/list")
    public Map  list(){
        JsonResult jsonResult = new JsonResult();
        Map list = typeTableService.list();
        if (list == null){
            throw new BusinessException("查询失败");
        }
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.put("list",list.get("list"));
        return jsonResult.getValues();
    }



}
